package 多线程01_启动线程;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName: TicketThread
 * @Author: AllenSun
 * @Date: 2022/3/20 下午4:55
 */
public class TicketThread implements Runnable {

    private int ticketNum = 10;
    AtomicInteger atomicI =new AtomicInteger();

    @Override
    public void run() {
        while (true) {
            if(ticketNum<=0){
                break;
            }
            synchronized (this) {
                System.out.println(Thread.currentThread().getName()+" 抢到了第"+ticketNum--+"张票");
            }
        }
    }

    public static void main(String[] args) {
        TicketThread ticketThread = new TicketThread();
        new Thread(ticketThread,"小明").start();
        new Thread(ticketThread,"老王").start();
        new Thread(ticketThread,"黄牛").start();
    }
}
